<?php
defined('ROOT') or die('No direct script access.');
class {TemplateManagerName} extends CModel
{
    public function get_by_id($prm_id)
    {
        $data = self::fetch("select * from ##_{TemplateTableName} where ID = :id", array('id'=> $prm_id), '{TemplateRecordName}');
        return $data;
    }

    public function get_list($params=0)
    {
        if (isset($params['page'])) {
            $page = $params['page'];
        } else {
            $page = -1;
        }
        if (isset($params['limit'])) {
            $limit = min($params['limit'],100);
        } else {
            $limit = 20;
        }
        $sql_cond = "";
        $sql_text = "
			SELECT
			    tbl.*
			from
				##_{TemplateTableName} as tbl " . $sql_cond;
        if ($page != -1) {
            $sql_text .= " limit " . (($page - 1) * $limit) . ", " . $limit;
        }
        $rows = self::fetch_all($sql_text, 0, '{TemplateRecordName}');
        $count_recs = self::fetch("select count(id) cnt from ##_{TemplateTableName} " . $sql_cond);
        return array('rows'=> $rows, 'count'=> $count_recs->cnt);
    }

    public function del($param)
    {
        $id = intval(self::escape($param['id']));
        $data = array(
            'id' => $id,
        );
        $sql = "delete from ##_{TemplateTableName} where id = :id";
        self::execute($sql, $data);
    }
}

?>